package stream.part3;

import java.util.Optional;
import java.util.stream.Stream;

public class Demo04 {
    public static void main(String[] args) {
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5, 6);

        System.out.println(addUp(integerStream));
    }

    private static int addUp(Stream<Integer> numbers) {
        Optional<Integer> reduce = numbers.reduce(Integer::sum);
        return reduce.orElse(0);
    }
}
